home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
mndlbrot.zip
/
MNDLBR.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-02-19
|
8KB
|
240 lines
{ MANDELBROT
[Downloaded from Delaware OPUS 17 Feb 87 as MNDLBR.PAS.
Toad Hall
]
This program generates and displays Mandelbrots. A Mandelbrot is a
graphic representation of the mandelbrot set and the fleeing points
around the set on the REAL/IMAGINARY plane. Mathmatically, a point
in the set is defined as a point which when iterated in the following
manner will remain finite after an infinite number of iterations:
1. c := point; z := 0; n := 0;
2. z := z*z + c;
3 n := n+1;
4. repeat until either z>2 or n is some large number
Obviously the iteration cannot be carried out to infinity so we set an
upper limit to 255. Thus "n" can just fit in one byte. Typically large
computers will only carry n to 1000, and there is very little difference
between 255 and 1000 iterations.
The Mandelbrot set representation is a breathtakingly beautiful thing. You
are encouraged to try and find an issue of August 1985 Scientific American
for some really fantastic photos, as well as a well written article.
To operate the program just answer the questions. A "C" will allow you
to generate a mandelbrot and a "D" will allow you to display it with different
"Breakpoints". The IBM can only display 4 colors and 255 is defined as black.
You must enter 2 breakpoints: a lower and an upper.
When n is between 0 and the lower breakpoint, color 1 will be displayed;
between breakpoint 1 and 2, color 2 will be displayed;
and when between 2 and 255, the third color is displayed.
Generating a file will usually require from 6 to 12 hours, or if an 8087
chip is used (and Turbo 8087 is used for compiling) the time is cut to
"only" 2 to 4 hours.
It is recommended that the full Mandelbrot be computed first
(RL,RU,IL,IU = -2,.5,-1.25,1.25), then blowups done from it.
Remember to enter a carriage return after each number.
A disk for the IBM and compatibles which has this program and about 6 of the
really good plots on it is available for $5 to cover the cost of the disk and
shipping.
A disk with an advanced version of this program which allows windowing
of an area in the display, so referencing is done automatically to
the generate portion for an easy magnification of a specific area,
is available for $15.
The advanced version will have standard as well as 8087 com files
and includes many more features, as well as color pictures of several
Mandelbrots and updates when new features are added.
To order or report bugs Reply to: Marshall Dudley or Compuserve
12402 W. Kingsgate Dr. #72416,3357
Knoxville, Tn. 37922
This program may be duplicated and given away free provided
this introduction is left untouched.
Modifications: You may wish to try some modifications to this program.
If this program is modified please indicate who and what mods were done below.
I would be interested in hearing about any good mods and can be reached as
above.
Please do not change the file structure. It was done in this manner so that
a file can be created and displayed by standard or 8087 turbo interchangeably.
A change will cause compatibility problems.
}
PROGRAM Mandelbrot;
{$U-}
TYPE
Special = STRING[23];
chunk = RECORD
Val1:Special;
Val2:Special;
Val3:Special;
Val4:Special;
littlechunk : ARRAY[0..319,0..199] OF Byte;
END;
CONST
Beep :CHAR = ^G;
VAR
XPic,YPic,Color :INTEGER;
RealUpper,RealLower,ImagUpper,ImagLower :REAL;
Name :STRING[20];
N : Byte;
chunkfile : FILE OF chunk;
ChunkRec : Chunk;
c,choice : CHAR;
PROCEDURE Generate;
VAR
RealPart,Imaginary,ZR,ZI,StepX,StepY,ZrSquared,ZISquared :REAL;
BEGIN
WRITELN('Enter Lower and upper limits of Real & Imaginary parts');
WRITELN('as:RL,RU,IL,IU each followed by a CR.');
READLN(RealLower);
READLN(RealUpper);
READLN(ImagLower);
READLN(ImagUpper);
WRITELN('Enter filename:');
READLN(Name);
GraphColorMode;
StepX:=(RealUpper-RealLower)/320.0;
StepY:=(ImagUpper-ImagLower)/200.0;
FOR Xpic := 0 TO 319 DO
BEGIN
FOR Ypic := 0 TO 199 DO
BEGIN
N:=0;
ZR:=0;
ZI:=0;
Plot(XPic-1,YPic-1,3);
RealPart:=RealLower+INT(Xpic)*Stepx;
Imaginary:=ImagLower+INT(Ypic)*StepY;
ZrSquared:=0;
ZISquared:=0;
REPEAT
ZI:=ZI*ZR*2+imaginary;
Zr:=ZrSquared+REALPart-ZISquared;
N:=N+1;
ZrSquared:=SQR(Zr);
ZISquared:=SQR(ZI);
UNTIL ((ZrSquared+ZISquared)>4) OR (N>254);
Color:=3-(N ShR 6); {make 0 to 255 into 15 to 0 for graphing}
Plot(XPic-1,Ypic-1,Color);
ChunkRec.LittleChunk[xpic,ypic]:=n;
END;
IF KeyPressed THEN
BEGIN
READ(Kbd,c);
IF c = CHR(3) THEN HALT;
END;
END;
TextMode;
WRITE(beep); {Beep at finish}
STR(RealLower:23,ChunkRec.Val1);
STR(RealUpper:23,ChunkRec.Val2);
STR(ImagLower:23,ChunkRec.Val3);
STR(ImagUpper:23,ChunkRec.Val4);
Assign(chunkfile,Name);
REWRITE(chunkfile);
WRITE(chunkfile,ChunkRec);
CLOSE(chunkfile);
WRITE(beep);
END;
PROCEDURE Print;
VAR
RealUpper,RealLower,ImagUpper,ImagLower :REAL;
N :Byte;
z :STRING[10];
Breakpoint1,Breakpoint2,EPosition,Palet,error :INTEGER;
FUNCTION Value(numstring: Special) : REAL;
VAR
temporary : REAL;
BEGIN
IF Numstring[21]='0' THEN DELETE(numstring,21,1); {If written by 8087 version}
REPEAT
DELETE(numstring,1,1);
UNTIL ORD(NumString[1])<>32; {delete spaces}
VAL(NumString,temporary,error);
Value := temporary;
END;
BEGIN
WRITELN('Enter Filename for data');
READLN(Name);
Assign(Chunkfile,Name);
RESET(Chunkfile);
READ(Chunkfile,ChunkRec);
CLOSE(ChunkFile);
RealLower:=Value(ChunkRec.Val1);
RealUpper:=Value(ChunkRec.Val2);
ImagLower:=Value(ChunkRec.Val3);
ImagUpper:=Value(ChunkRec.Val4);
WRITELN('Real Boundries are: ',RealLower:10:8,' ',RealUpper:10:8);
WRITELN('Imaginary Boundries: ',ImagLower:10:8,' ',ImagUpper:10:8);
WRITELN('255 will be black, Enter breakpoints for other two shades');
READLN(Breakpoint1);
READLN(Breakpoint2);
WRITELN('When display is complete enter a "P" to change palettes or');
WRITELN('any other character to exit. Enter return to display plot');
READ(z);
GraphColorMode;
FOR Xpic := 0 TO 319 DO
BEGIN
FOR Ypic := 0 TO 199 DO
BEGIN
N:=ChunkRec.LittleChunk[xpic,ypic];
IF N=255 THEN Color := 0
ELSE
IF N<Breakpoint1 THEN Color := 3
ELSE
IF (N<Breakpoint2) THEN Color := 2
ELSE Color := 1;
Plot(XPic,Ypic,Color);
END;
END;
Palet := 0;
REPEAT
READ(Kbd,c); {wait for an entry before erasing screen}
Palet := (Palet+1) AND 3;
IF UpCase(c) = 'P' THEN Palette(Palet);
UNTIL UpCase(c) <> 'P';
TextMode;
END;
BEGIN
REPEAT
ClrScr;
WRITE('(C)reate a Mandelbrot file, (D)isplay a file or (E)xit ? ');
REPEAT READ(Kbd,choice) UNTIL UpCase(choice) IN['C','D','E'];
WRITELN;
CASE Choice OF
'c','C' :Generate;
'd','D' :Print;
END;
UNTIL UpCase(choice) = 'E';
END.